package Reports;


import java.sql.Connection;

import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.view.JasperViewer;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JRException;


public abstract class AbstractJasperReports
{
	private static JasperReport	report; //reporte o ruta de informe
	private static JasperPrint	reportFilled; //donde se almacena el resultado del query
	private static JasperViewer	viewer;  //visor que muestra el reporte.
	

	public static void createReport( Connection conn, String path )
	{
		try {
			report = (JasperReport) JRLoader.loadObjectFromFile( path );
			reportFilled = JasperFillManager.fillReport( report, null, conn );
		}
		catch( JRException ex ) {
			ex.printStackTrace();
		}
	}

	public static void showViewer()
	{
		viewer = new JasperViewer( reportFilled ); // podia ser asi tambien 'new JasperViewer( reportFilled, false );'
		viewer.setVisible( true ); //el true o false es para la visibilidad
	}

	public static void exportToPDF( String destination )
	{
		try { 
			JasperExportManager.exportReportToPdfFile( reportFilled, destination );
		}
		catch( JRException ex ) {
			ex.printStackTrace();
		}
	}
	
}
